package club.kingyin.easycache.component.annotation.handler;

import club.kingyin.easycache.cache.AbstractCache;
import club.kingyin.easycache.cache.union.Level2Cache;
import club.kingyin.easycache.key.EasyCacheKey;
import club.kingyin.easycache.method.CacheMethod;
import club.kingyin.easycache.proxy.ProxyCacheInvokePostProcess;

/**
 * 该模块视作二级缓存的探索先驱，对已有功能无影响（仅扩展）
 * 注意：由于该方案在测试中表现出来的结果和预期有一定的差异，目前已将二级缓存模块废弃
 */
public class ModuleRegisToRedisHandler implements ProxyCacheInvokePostProcess {
    @Override
    public boolean getCacheInterceptor(boolean pre, CacheMethod target, EasyCacheKey key) {
        return pre;
    }

    @Override
    public void postProcessAfterGetCache(CacheMethod target, AbstractCache cache, Object res, EasyCacheKey key) {
        if (cache.getDatabase() instanceof Level2Cache) {
            ((Level2Cache) cache.getDatabase()).register(key.getModule());
        }
    }
}
